package coalition.formation.combinations;

import java.util.ArrayList;
import java.util.List;

public class IndexedCombination {

	public static void main(String[] args) {
		
		List<int[]> unindexedCombinations =
			Combination.findCombinations(4, 6);
		System.out.println("raw indexed combinations");
		for(int[] combination : unindexedCombinations)
			System.out.println("" + coalition.formation.utils.Util.printIntArray(combination));
		
		System.out.println("indexed combinations");
		List<int[]> indexedCombinations =
			findCombinations(4, 6, new int[]{10, 200, 3000, 40000, 500000, 6000000});
		for(int[] combination : indexedCombinations)
			System.out.println("" + coalition.formation.utils.Util.printIntArray(combination));
	}
	
	//return non-zero size combinations
	public static List<int[]> findCombinations(int combinationSize, int setSize, int[] indices){
		List<int[]> combinations = Combination.findCombinations(combinationSize, setSize);
		return convertToIndexedCombinations(combinations, indices);
	}
	
	//return non-zero size combinations
	public static List<int[]> findCombinations(int setSize, int[] indices){
		List<int[]> combinations = Combination.findCombinations(setSize);
		return convertToIndexedCombinations(combinations, indices);
	}	
	
	private static List<int[]> convertToIndexedCombinations(List<int[]> combinations, int[] indices){
		List<int[]> indexCombinations = new ArrayList<int[]>();
		int[] indexedCombination;
		for(int[] combination : combinations){
			//don't add zero size combinations
			if(combination.length == 0) continue;
			indexedCombination = new int[combination.length];
			for(int i = 0; i < combination.length; i++)
				indexedCombination[i] = indices[combination[i]];
			indexCombinations.add(indexedCombination);
		}
		return indexCombinations;		
	}
	
}
